package com.bball.court.http;

import android.content.Context;
import android.util.Log;

import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.bball.court.http.base.GsonDeleteRequest;
import com.bball.court.model.Court;
import com.bball.court.model.CourtList;
import com.bball.court.model.google.GoogleCourtInstanceCreator;
import com.bball.court.model.google.GoogleCourtListInstanceCreator;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class DeleteCourtRequest extends GsonDeleteRequest<Court> {

    public DeleteCourtRequest(Context context, String url, String tag, final DeleteCourtRequestCallbacks callbacks) {
        super(context, url, Court.class, tag, new Listener<Court>() {
            @Override
            public void onResponse(Court court) {
                callbacks.onDeleteCourtsComplete(court.getCourtId());
            }
        }, new ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e(getClass().getSimpleName(), error.getMessage(), error);
                callbacks.onDeleteCourtsFailed(new RuntimeException(error));
            }
        });
    }

    @Override
    protected Gson getGson(Context context) {
        return new GsonBuilder().registerTypeAdapter(Court.class, new GoogleCourtInstanceCreator())
                .registerTypeAdapter(CourtList.class, new GoogleCourtListInstanceCreator()).create();
    }

}
